package com.chinasofti.set03;

public class Student implements Comparable<Student>{

    private String name ;
    private int chinese ;
    private int math ;
    private int english ;

    public Student() {
    }

    public Student(String name, int chinese, int math, int english) {
        this.name = name;
        this.chinese = chinese;
        this.math = math;
        this.english = english;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getChinese() {
        return chinese;
    }

    public void setChinese(int chinese) {
        this.chinese = chinese;
    }

    public int getMath() {
        return math;
    }

    public void setMath(int math) {
        this.math = math;
    }

    public int getEnglish() {
        return english;
    }

    public void setEnglish(int english) {
        this.english = english;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", chinese=" + chinese +
                ", math=" + math +
                ", english=" + english +
                '}';
    }
    public int getSum(){
        return this.chinese+this.english+this.math;
    }

    @Override
    public int compareTo(Student o) {
        //主要条件，比总分
        int result = o.getSum() - this.getSum();
        //总分一样 比 语文
        result = result == 0 ? o.getChinese() - this.getChinese():result;
        //语文一样， 比数学
        result = result == 0 ? o.getMath() - this.getMath():result;
        //如各科成绩一致 按照姓名排序
        result = result == 0 ? o.getName().compareTo(this.getName()):result;
        return result;
    }
}
